package app.modules.common.enums;

import app.modules.common.constant.CommonMsgConstants;
import jasmine.framework.i18n.I18nKeyAndArgs;

import javax.annotation.Nullable;

/**
 * @author mh.z
 */
public enum EffectiveFlagEnum implements I18nKeyAndArgs {
    TRUE("TRUE", true, CommonMsgConstants.EFFECTIVE_FLAG_TRUE),
    FALSE("FALSE", false, CommonMsgConstants.EFFECTIVE_FLAG_FALSE);

    private String code;
    private Boolean value;
    private String i18nKey;

    EffectiveFlagEnum(String code, Boolean value, String i18nKey) {
        this.code = code;
        this.value = value;
        this.i18nKey = i18nKey;
    }

    public String getCode() {
        return code;
    }

    public Boolean getValue() {
        return value;
    }

    @Override
    public String getI18nKey() {
        return i18nKey;
    }

    public boolean codeEquals(@Nullable String code) {
        return this.code.equals(code);
    }

    public static EffectiveFlagEnum parseCode(@Nullable String code) {
        if (code == null) {
            return null;
        }

        return valueOf(code);
    }

    public static EffectiveFlagEnum parseValue(@Nullable Boolean value) {
        if (value == null) {
            return null;
        }

        EffectiveFlagEnum result = null;

        if (Boolean.TRUE.equals(value)) {
            result = EffectiveFlagEnum.TRUE;
        } else if (Boolean.FALSE.equals(value)) {
            result = EffectiveFlagEnum.FALSE;
        }

        return result;
    }

}
